<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AdminUser extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change (): void {
        $table = $this->table('admin_user', [
            'collation' => 'utf8mb4_general_ci'
        ]);
        $table->addColumn('username', 'string', [
            'limit' => 32, 'null' => false, 'default' => '', 'comment' => '用户名'
        ]);
        $table->addColumn('mobile', 'string', [
            'limit' => 11, 'null' => false, 'default' => '', 'comment' => '手机号'
        ]);
        $table->addColumn('gender', 'integer', [
            'limit' => 1, 'null' => false, 'default' => '0', 'comment' => '性别 0未知 1男 2女'
        ]);
        $table->addColumn('avatar', 'string', [
            'limit' => 255, 'null' => false, 'default' => '', 'comment' => '用户头像'
        ]);
        $table->addColumn('password', 'string', [
            'limit' => 255, 'null' => false, 'default' => '', 'comment' => '密码'
        ]);
        $table->addColumn('full_name', 'string', [
            'limit' => 32, 'null' => false, 'default' => '', 'comment' => '姓名'
        ]);
        $table->addColumn('post_name', 'string', [
            'limit' => 32, 'null' => false, 'default' => '', 'comment' => '岗位'
        ]);
        $table->addColumn('status', 'integer', [
            'limit' => 1, 'null' => false, 'default' => '1', 'comment' => '用户状态: 1正常 2锁定'
        ]);
        $table->addColumn('login_time', 'datetime', [
            'comment' => '登录时间'
        ]);
        $table->addColumn('login_ip', 'string', [
            'limit' => 15, 'null' => false, 'default' => '', 'comment' => '登录IP'
        ]);
        $table->addColumn('create_time', 'datetime', [
            'comment' => '创建时间'
        ]);
        $table->addColumn('update_time', 'datetime', [
            'comment' => '更新时间'
        ]);
        $table->addColumn('delete_time', 'datetime', [
            'comment' => '删除时间'
        ]);
        $table->addIndex(['username'], ['name' => 'idx_username']);
        $table->addIndex(['mobile'], ['name' => 'idx_mobile']);
        $table->create();
    }
}
